package com.rustic.server.enums;

import cn.hutool.core.text.CharSequenceUtil;
import cn.xy.commons.validator.VerifiedEnum;
import lombok.Getter;

/**
 * @author jianzheng
 */

@Getter
public enum GenderEnum implements VerifiedEnum {

    /**
     * 未知
     */
    UNKNOWN(0, "未知"),

    /**
     * 男
     */
    MAN(1, "男"),

    /**
     * 女
     */
    WOMAN(2, "女");

    private final int value;

    private final String name;

    GenderEnum(int value, String name) {
        this.value = value;
        this.name = name;
    }

    public static String getNameByValue(int gender) {
        for (GenderEnum genderEnum : GenderEnum.values()) {
            if (gender == genderEnum.getValue()) {
                return genderEnum.getName();
            }
        }
        return UNKNOWN.getName();
    }

    public static int getValueByName(String gender) {
        if (CharSequenceUtil.isEmpty(gender)) {
            return UNKNOWN.getValue();
        }
        for (GenderEnum genderEnum : GenderEnum.values()) {
            if (gender.equals(genderEnum.getName())) {
                return genderEnum.getValue();
            }
        }
        return UNKNOWN.getValue();
    }

    @Override
    public Object getVerifiedValue() {
        return this.value;
    }

}
